import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_cropper/image_cropper.dart';
import 'package:image_picker/image_picker.dart';
import 'package:mediapipe_task_vision_example/page/pose_image.dart';
import 'package:mediapipe_task_vision_example/util/utils.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<HomePage> {
  @override
  void initState() {
    init();
    super.initState();
  }

  init() async {
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: const Text("Mediapipe")),
        body: Column(mainAxisSize: MainAxisSize.min, children: [
          const SizedBox(height: 120.0),
          Row(
            children: [
              Expanded(
                  child:
                      Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
                IconButton(
                    icon: const Icon(Icons.photo_camera),
                    iconSize: 48,
                    onPressed: () async {
                      String croppedFile =
                          await Utils().getImgByCamera(context);
                      if (croppedFile != null) {
                        Navigator.push(context, MaterialPageRoute(builder: (c) {
                          return PoseImageWidget(croppedFile);
                        }));
                      }
                    }),
                const Text('相机')
              ])),
              Expanded(
                  child:
                      Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
                IconButton(
                    icon: const Icon(Icons.photo_album),
                    iconSize: 48,
                    onPressed: () async {
                      String croppedFile =
                          await Utils().getImgByGallery(context);
                      if (croppedFile != null) {
                        Navigator.push(context,
                            MaterialPageRoute(builder: (context) {
                          return PoseImageWidget(croppedFile);
                        }));
                      }
                    }),
                const Text('相册')
              ])),
            ],
          )
        ]));
  }
}
